package com.woniuxy.config;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.CustomExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.HashMap;
import java.util.Map;

/**
 * @Author: 马宇航
 * @Do: 延迟队列配置类
 * @DateTime: 22/07/07/0007 下午 2:43
 * @Component: 成都蜗牛学苑
 **/
@Configuration
public class DelayQueueConfig {
    //配置自定义延迟交换机
    @Bean
    public CustomExchange delayExchange(){
        Map args = new HashMap<>();
        //延迟交换机类别 topic 模糊匹配
        args.put("x-delayed-type","topic");
        //返回自定义交换机 name，type就是我们交换机的类别
        return new CustomExchange("delayExchange","x-delayed-message",true,false,args);
    }
    //创建一个普通队列
    @Bean
    public Queue delayQueue(){
        return new Queue("delayQueue");
    }
    //binding他们
    @Bean
    public Binding delayBinding(){
        return BindingBuilder.bind(delayQueue()).to(delayExchange()).with("delay.#").noargs();
    }
}
